using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace Triton.Common.Math
{
	public static class Misc
	{
		public delegate bool PlotFunction(int x, int y);

		[CompilerGenerated]
		private sealed class Class239
		{
			public List<Vector2i> list_0;

			internal bool method_0(int int_0, int int_1)
			{
				list_0.Add(new Vector2i(int_0, int_1));
				return true;
			}
		}

		private static void smethod_0<T>(ref T gparam_0, ref T gparam_1)
		{
			T val = gparam_0;
			gparam_0 = gparam_1;
			gparam_1 = val;
		}

		public static List<Vector2i> GetPointsOnSegment(Vector2i start, Vector2i end)
		{
			List<Vector2i> list_0 = new List<Vector2i>();
			PlotFunction plotFunction = delegate(int int_0, int int_1)
			{
				list_0.Add(new Vector2i(int_0, int_1));
				return true;
			};
			int gparam_ = start.X;
			int gparam_2 = start.Y;
			int gparam_3 = end.X;
			int gparam_4 = end.Y;
			bool flag;
			if (flag = System.Math.Abs(gparam_4 - gparam_2) > System.Math.Abs(gparam_3 - gparam_))
			{
				smethod_0(ref gparam_, ref gparam_2);
				smethod_0(ref gparam_3, ref gparam_4);
			}
			if (gparam_ > gparam_3)
			{
				smethod_0(ref gparam_, ref gparam_3);
				smethod_0(ref gparam_2, ref gparam_4);
			}
			int num = gparam_3 - gparam_;
			int num2 = System.Math.Abs(gparam_4 - gparam_2);
			int num3 = num / 2;
			int num4 = ((gparam_2 < gparam_4) ? 1 : (-1));
			int num5 = gparam_2;
			int num6 = gparam_;
			while (true)
			{
				if (num6 <= gparam_3)
				{
					if (!(flag ? plotFunction(num5, num6) : plotFunction(num6, num5)))
					{
						break;
					}
					num3 -= num2;
					if (num3 < 0)
					{
						num5 += num4;
						num3 += num;
					}
					num6++;
					continue;
				}
				if (list_0[0].Distance(start) > list_0[list_0.Count - 1].Distance(start))
				{
					list_0.Reverse();
				}
				return list_0;
			}
			return list_0;
		}

		public static List<Vector2i> Humanize(Vector2i start, Vector2i end, int dist = 8)
		{
			List<Vector2i> list = new List<Vector2i>();
			Vector2i vector2i = end - start;
			vector2i.Normalize();
			int num = (int)System.Math.Floor((float)start.Distance(end) / (float)dist);
			for (int i = 1; i < num; i++)
			{
				Vector2i vector2i2 = start + vector2i * (dist * i);
				list.Add(new Vector2i(vector2i2.X, vector2i2.Y));
			}
			list.Add(new Vector2i(end.X, end.Y));
			return list;
		}
	}
}
